unit uFrmVehicleModel;

interface

uses
  SysUtils, Classes, Variants, Windows, Messages, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, DLXButtons, uCxtConst, uCxtTypes, uCxtForm;

type
  TFrmVehicleModel = class(TBaseForm)
    Panel1: TPanel;
    pnlInfo: TPanel;
    GroupBox1: TPanel;
    Label1: TLabel;
    rgCSPP: TRadioGroup;
    Panel2: TPanel;
    Label7: TLabel;
    rgTGGZ: TRadioGroup;
    Panel3: TPanel;
    Label9: TLabel;
    rgHSJG: TRadioGroup;
    Panel4: TPanel;
    Label5: TLabel;
    rgTSGN: TRadioGroup;
    pnlAction: TPanel;
    BtnOk: TButton;
    BtnCancel: TButton;
    procedure FormCreate(Sender: TObject);
  private
    function GetVehicleModel: string;
    procedure SetVehicleModel(const Value: string);
    procedure SetSingle(rg: TRadioGroup; const text: string);
  public
    property VehicleModel: string read GetVehicleModel write SetVehicleModel;
  end;

function SelectVehicleModel(var model: string): Boolean;

implementation

{$r *.dfm}

var
  FrmVehicleModel: TFrmVehicleModel;

function SelectVehicleModel(var model: string): Boolean;
begin
  if not Assigned(FrmVehicleModel) then
    FrmVehicleModel := TFrmVehicleModel.Create(Application);
  FrmVehicleModel.VehicleModel := model;
  if mrOk = FrmVehicleModel.ShowModal then
  begin
    model := FrmVehicleModel.VehicleModel;
    Result := True;    
  end
  else Result := False;
end;

{ TFrmVehicleModel }

procedure TFrmVehicleModel.FormCreate(Sender: TObject);
begin
  rgTGGZ.Items.Delimiter := ';';
  rgTGGZ.Items.DelimitedText := gc_TuoGuaJiLunZhou;
  rgTGGZ.ItemIndex := rgTGGZ.Items.Count - 1;
  rgHSJG.Items.Delimiter := ';';
  rgHSJG.Items.DelimitedText := gc_HuoXiangJieGou;
  rgHSJG.ItemIndex := rgHSJG.Items.Count - 1;
  rgTSGN.Items.Delimiter := ';';
  rgTSGN.Items.DelimitedText := gc_TeShuGongNeng;
  rgTSGN.ItemIndex := rgTSGN.Items.Count - 1;
  rgCSPP.Items.Delimiter := ';';
  rgCSPP.Items.DelimitedText := gc_ChangShangPinPai;
  rgCSPP.ItemIndex := rgCSPP.Items.Count - 1;
end;

function TFrmVehicleModel.GetVehicleModel: string;
begin
  Result := rgTGGZ.Items[rgTGGZ.ItemIndex] + ',' +
    rgHSJG.Items[rgHSJG.ItemIndex] + ',' +
    rgTSGN.Items[rgTSGN.ItemIndex] + ',' +
    rgCSPP.Items[rgCSPP.ItemIndex];
end;

procedure TFrmVehicleModel.SetSingle(rg: TRadioGroup; const text: string);
begin
  rg.ItemIndex := rg.Items.IndexOf(text);
  if (rg.ItemIndex = -1) then rg.ItemIndex := rg.Items.Count - 1;   
end;

procedure TFrmVehicleModel.SetVehicleModel(const Value: string);
var
  sl: TStrings;
begin
  sl := TStringList.Create;
  try
    sl.Delimiter := ',';
    sl.DelimitedText := Value;
    if (sl.Count > 0) then SetSingle(rgTGGZ, sl[0]);
    if (sl.Count > 1) then SetSingle(rgHSJG, sl[1]);
    if (sl.Count > 2) then SetSingle(rgTSGN, sl[2]);
    if (sl.Count > 3) then SetSingle(rgCSPP, sl[3]);
  finally
    sl.Free;
  end;
end;

end.
